/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-06-13 18:19:21
 * @LastEditTime: 2019-07-01 09:23:37
 * @LastEditors: Please set LastEditors
 */

import {
    HTTP
} from "../utils/https.js";
import {
    config
} from "../config.js";

class User extends HTTP {
    /**
     * @description: wx登录 换取token
     * @param {res.code}
     */
    getToken(code, pid) {
        return this.request({
            url: config.userLogin,
            data: {
                code,
                pid
            },
            hastoken: 0
        })
    }

    /**
     * @description: 检测token 有效期
     * @param {token} 
     */
    indateToken() {
        return this.request({
            url: config.checkLogin,
        })
    }


    /**
     * @description:  获取购物车
     * @param {shop_id,order_type} 
     */

    getCarList(shop_id, order_type) {
        return this.request({
            url: config.getCarList,
            data: {
                shop_id: shop_id,
                order_type: order_type
            }
        });
    }


    /**
     * @description:  获取收货地址
     * @param {address_id 传参获取当前 不传获取所有}  
     */
    getSite(address_id) {
        return this.request({
            url: config.getSite,
            data: {
                address_id
            }
        });
    }

    /**
     * @description:  添加收货地址
     * @param {region:[] 区域} 
     */
    addSite(truename, sex, mobile, address, region, isdefault) {
        return this.request({
            url: config.addSite,
            data: {
                truename,
                sex,
                mobile,
                address,
                region,
                isdefault
            }
        });
    }

    /**
     * @description:  修改保存地址
     * @param {region:[] 区域} 
     */
    saveSite(truename, sex, mobile, address, region, isdefault) {
        return this.request({
            url: config.saveSite,
            data: {
                truename,
                sex,
                mobile,
                address,
                region,
                isdefault
            }
        });
    }

    /**
     * @description:  删除收货地址
     * @param {aid 地址id } 
     */
    delSite(aid) {
        return this.request({
            url: config.delSite,
            data: {
                aid
            }
        });
    }

    /**
     * @description:  获取我可用的优惠券
     */
    getMyCoupon() {
        return this.request({
            url: config.getMyCoupon
        });
    }


    /**
     * @description:  添加购物车
     * @param {type} 
     */
    addCar(gid, shop_id, order_type, attr_id = 0, attr_value = "") {
        return this.request({
            url: config.addCar,
            data: {
                gid,
                shop_id,
                order_type,
                attr_id,
                attr_value
            }
        });
    }

    /**
     * @description:  购物车减少
     * @param {type} 
     */
    cutCar(gid, shop_id, order_type, attr_id = 0, attr_value = "") {
        return this.request({
            url: config.cutCar,
            data: {
                gid,
                shop_id,
                order_type,
                attr_id,
                attr_value
            }
        });
    }


    /**
     * @description:  下单支付
     * @param { address_id,coupon_id,date,deskid,jc_count,location, ordertype,paytype,remark,shops,time,lastpay,mobile} 
     */
    placeOrder(address_id, coupon_id, date, deskid, jc_count, location, ordertype, paytype, remark, shops, time, lastpay, mobile) {
        return this.request({
            url: config.placeOrder,
            data: {
                address_id,
                coupon_id,
                date,
                deskid,
                jc_count,
                location,
                ordertype,
                paytype,
                remark,
                shops,
                time,
                lastpay,
                mobile
            }
        })
    }


    /**
     * @description:  取消订单
     */
    cancelOrder(oid) {
        return this.request({
            url: config.cancelOrder,
            data: {
                oid
            }
        })
    }

    /**
     * @description:  店内加菜  
     */
    addDish(oid, shopid) {
        return this.request({
            url: config.addDish,
            data: {
                oid,
                shopid
            }
        })
    }

    /**
     * @description:  余额支付
     * @param {oid} 
     */
    payForBalance(oid) {
        return this.request({
            url: config.payForBalance,
            data: {
                oid
            }
        })
    }

    /**
     * @description:  充值 支付(微信)
     * @param {} 
     */
    wxPay(amount, oid) {
        return this.request({
            url: config.wxPay,
            data: {
                amount,
                oid
            }
        })
    }


    /**
     * @description:  绑定用户信息
     * @param {type} 
     * @return: 
     */
    bindUser(Birthday, Mobile, SystemInfo, avatarUrl, city, gender, nickName, province) {
        return this.request({
            url: config.bindUser,
            data: {
                Birthday,
                Mobile,
                SystemInfo,
                avatarUrl,
                city,
                gender,
                nickName,
                province
            }
        })
    }

    /**
     * @description:  积分兑换
     */
    postExchange(id) {
        return this.request({
            url: config.postExchange,
            data: {
                id
            }
        });
    }

    /**
     * @description: 积分兑换记录
     */
    getExchangeList() {
        return this.request({
            url: config.getExchangeList
        });
    }

    /**
     * @description: 兑换订单详情
     *  @param {id:订单号} 
     */
    getExchangeInfo(id) {
        return this.request({
            url: config.getExchangeInfo,
            data: {
                id
            }
        });
    }

    /**
     * @description:  获取我可用的优惠券
     */
    getMyCoupon() {
        return this.request({
            url: config.getMyCoupon,
        });
    }

    /**
     * @description:  获取我所有的优惠券
     * @param {token}
     * @return:
     */
    getMyCouponAll(page) {
        return this.request({
            url: config.getMyCouponAll,
            data: {
                page
            }
        });
    }

    /**
     * @description:  获取订单列表 个人
     */
    getOrderList(type, page) {
        return this.request({
            url: config.getOrderList,
            data: {
                type,
                page
            }
        });
    }

    /**
     * @description:  获取订单详情 个人
     */
    getOrderDetail(oid) {
        return this.request({
            url: config.getOrderDetail,
            data: {
                oid
            }
        });
    }
    /**
     * @description:  获取订单列表 商家
     */
    getOrderListAd(type, page) {
        return this.request({
            url: config.getOrderListAd,
            data: {
                type,
                page
            }
        });
    }

    /**
     * @description:  获取订单详情 商家
     */
    getOrderDetailAd(id) {
        return this.request({
            url: config.getOrderDetailAd,
            data: {
                id
            }
        });
    }

    /**
     * @description:  根据桌号-获得目前正在就餐的订单
     * @return: 
     */
    getDiningInfo(deskid) {
        return this.request({
            url: config.getDiningInfo,
            data: {
                deskid
            }
        })
    }



    /**
     * @description:  路线规划
     * @param {type}  
     * @return: 
     */
    getRoutePlanning(from, to) {
        return this.request({
            url: config.getRoutePlanning,
            data: {
                from,
                to
            }
        })
    }

    /**
     * @description:  获取分店营业信息
     * @param {type:int  1:今天的数据 2:当月数据 3:所有数据} 
     */
    getShopInfoAd(type) {
        return this.request({
            url: config.getShopInfoAd,
            data: {
                type
            }
        })
    }


    /**
     * @description: 获得代言人基本信息
     */
    getSpokesmanInfo() {
        return this.request({
            url: config.getSpokesmanInfo
        })
    }

    /**
     * @description: 获得我的粉丝佣金收益
     */
    getMyFansBrokerage(page) {
        return this.request({
            url: config.getMyFansBrokerage,
            data: {
                page
            }
        })
    }

    /**
     * @description:  获取骑手申请列表
     */
    getRiderList() {
        return this.request({
            url: config.getRiderList,
        })
    }



}

export {
    User
}